/*  ----------------------------------------------------------------------------
 *  Arello Mobile
 *  Fast 3d Engine
 *  ----------------------------------------------------------------------------
 * Except where otherwise noted, this work is licensed under
 * http://creativecommons.org/licenses/by/3.0
 */

#ifndef __LIB3D_MESH_MESH_H__
#define __LIB3D_MESH_MESH_H__

#include <xml/Object.h>
#include <SharedRep.h>
#include <NoCopy.h>
#include <filesystem/String.hpp>
#include <lib3d/hard/IndexBuffer.h>
#include <lib3d/hard/VertexBuffer.h>
#include <lib3d/hard/Manager.h>
#include "Model.h"
#include <HardwareDependentObject.h>

namespace liba
{
namespace lib3d
{
namespace model
{

struct ModelInHardwareObject
{
	ModelInHardwareObject(hard::VertexBuffer * vb, hard::IndexBuffer * ib);
	~ModelInHardwareObject();

	hard::VertexBuffer * vb;
	hard::IndexBuffer * ib;
};

class ModelInHardware :
	public HardwareDependentObject<hard::Manager,ModelInHardwareObject>,
	public SharedPrecached<filesystem::String, Model>,
	public SharedPrecachedRepBase
{
public:
	ModelInHardware(const filesystem::String & name);
	~ModelInHardware();
	void render_to_list(const material::Shaders & shaders, hard::Hardware * hardware, hard::RenderList * render_list, const hard::RenderModel & model_ref);
	void render_to_shadow_list(const material::Shaders & shaders, hard::Hardware * hardware, hard::RenderList * render_list, const hard::RenderModel & model_ref);
	void fill_vb2(hard::Hardware * hardware, hard::RenderModel * model_ref);
	void load(const filesystem::String & name);
protected:
	virtual void on_add_hardware(hard::Manager::hardware_type * ha);
private:
	int total_primitives;
	int total_vertices;
	
	filesystem::String model_name;
	Sphere bounding_sphere;
	
	void start_loading();
	void stop_loading();
};

} // namespace model
} // namespace lib3d
} // namespace liba
using namespace liba;

#endif // __LIB3D_MESH_MESH_H__